package net.qiqb.core.executing;

import org.picocontainer.MutablePicoContainer;

public class ExecutingContextHolder {

    private static final ThreadLocal<ExecutingContext> ctx = new ThreadLocal<>();

    private static MutablePicoContainer container;


    /**
     * 获取当前命令执行的上下文
     *
     * @return 事件上下文环境
     */
    public static ExecutingContext current() {
        return ctx.get();
    }


    /**
     * 设置当前执行上下文
     *
     * @param executingContext
     */
    public static void setCurrent(ExecutingContext executingContext) {
        ctx.set(executingContext);
    }

    public static void removeCurrent() {
        if (ctx.get() == null || ctx.get().getParent() == null) {
            ctx.remove();
            return;
        }
        ctx.set(ctx.get().getParent());
    }


    public static void setContainer(MutablePicoContainer container) {
        ExecutingContextHolder.container = container;
    }


}
